﻿using System.Globalization;
using System.Reflection;

using Microsoft.Xna.Framework;

namespace xEngine.Utils
{
    public class Convert
    {
        #region Functions

        public static Vector2 V3ToV2xz(Vector3 v)
        {
            return new Vector2(v.X, v.Z);
        }
        public static Vector2 PointToV2(Point p)
        {
            return new Vector2(p.X, p.Y);
        }
        public static Vector3 PointToV3(Point p)
        {
            return new Vector3(p.X, 0, p.Y);
        }
        public static Vector3 ToVector3(object o)
        {
            string[] str = o.ToString().Split(',');
            return new Vector3(ToFloat(str[0].Trim()), ToFloat(str[1].Trim()), ToFloat(str[2].Trim()));
        }
        public static float ToFloat(object o)
        {
            return (float)System.Convert.ToDouble(o, CultureInfo.InvariantCulture);
        }
        public static int ToInt(object o)
        {
            return System.Convert.ToInt32(o, CultureInfo.InvariantCulture);
        }
        public static bool ToBool(object o)
        {
            return o.ToString().ToLower().Equals("true");
        }
        public static Color ToColor(object o)
        {
            PropertyInfo[] colorProperties = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public);

            foreach (PropertyInfo info in colorProperties)
                if (info.Name == o.ToString())
                    return (Color)info.GetValue(null, null);

            return Color.Black;
        }

        #endregion

        #region Enums
        #endregion
    }
}
